<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- abstractformbuilder.cpp -->
  <title>QAbstractFormBuilder Class | Qt Designer Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.14</a></td><td ><a href="qtdesigner-manual.html">Qt Designer Manual</a></td><td ><a href="qtdesigner-module.html">C++ Classes</a></td><td >QAbstractFormBuilder</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtdesigner-manual.html">Qt 5.14.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#protected-types">Protected Types</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QAbstractFormBuilder Class</h1>
<!-- $$$QAbstractFormBuilder-brief -->
<p>The QAbstractFormBuilder class provides a default implementation for classes that create user interfaces at run-time. <a href="#details">More...</a></p>
<!-- @@@QAbstractFormBuilder -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QAbstractFormBuilder&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += designer</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherited By:</td><td class="memItemRight bottomAlign"> <p><a href="qformbuilder.html">QFormBuilder</a></p>
</td></tr></table></div><ul>
<li><a href="qabstractformbuilder-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qabstractformbuilder.html#QAbstractFormBuilder-1">QAbstractFormBuilder</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qabstractformbuilder.html#dtor.QAbstractFormBuilder">~QAbstractFormBuilder</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qabstractformbuilder.html#errorString">errorString</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QWidget *</td><td class="memItemRight bottomAlign"><b><a href="qabstractformbuilder.html#load">load</a></b>(QIODevice *<i>device</i>, QWidget *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qabstractformbuilder.html#save">save</a></b>(QIODevice *<i>device</i>, QWidget *<i>widget</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qabstractformbuilder.html#setWorkingDirectory">setWorkingDirectory</a></b>(const QDir &amp;<i>directory</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDir </td><td class="memItemRight bottomAlign"><b><a href="qabstractformbuilder.html#workingDirectory">workingDirectory</a></b>() const</td></tr>
</table></div>
<a name="protected-types"></a>
<h2 id="protected-types">Protected Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qabstractformbuilder.html#DomPropertyHash-typedef">DomPropertyHash</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qabstractformbuilder.html#IconPaths-typedef">IconPaths</a></b></td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QAbstractFormBuilder-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>QAbstractFormBuilder provides a standard interface and a default implementation for constructing forms from user interface files. It is not intended to be instantiated directly. Use the <a href="qformbuilder.html">QFormBuilder</a> class to create user interfaces from UI files at run-time. For example:</p>
<pre class="cpp">

          MyForm<span class="operator">::</span>MyForm(<span class="type"><a href="../qtwidgets/qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
              : <span class="type"><a href="../qtwidgets/qwidget.html">QWidget</a></span>(parent)
          {
              <span class="type"><a href="qformbuilder.html">QFormBuilder</a></span> builder;
              <span class="type"><a href="../qtcore/qfile.html">QFile</a></span> file(<span class="string">&quot;:/forms/myWidget.ui&quot;</span>);
              file<span class="operator">.</span>open(<span class="type"><a href="../qtcore/qfile.html">QFile</a></span><span class="operator">::</span>ReadOnly);
              <span class="type"><a href="../qtwidgets/qwidget.html">QWidget</a></span> <span class="operator">*</span>myWidget <span class="operator">=</span> builder<span class="operator">.</span>load(<span class="operator">&amp;</span>file<span class="operator">,</span> <span class="keyword">this</span>);
              file<span class="operator">.</span>close();

              <span class="type"><a href="../qtwidgets/qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtwidgets/qvboxlayout.html">QVBoxLayout</a></span>;
              layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(myWidget);
              setLayout(layout);
          }

</pre>
<p>To override certain aspects of the form builder's behavior, subclass QAbstractFormBuilder and reimplement the relevant virtual functions:</p>
<ul>
<li><a href="qabstractformbuilder.html#load">load</a>() handles reading of UI format files from arbitrary QIODevices, and construction of widgets from the XML data that they contain.</li>
<li><a href="qabstractformbuilder.html#save">save</a>() handles saving of widget details in UI format to arbitrary QIODevices.</li>
<li><a href="qabstractformbuilder.html#workingDirectory">workingDirectory</a>() and <a href="qabstractformbuilder.html#setWorkingDirectory">setWorkingDirectory</a>() control the directory in which forms are held. The form builder looks for other resources on paths relative to this directory.</li>
</ul>
<p>The <a href="qformbuilder.html">QFormBuilder</a> class is typically used by custom components and applications that embed <i>Qt Designer</i>. Standalone applications that need to dynamically generate user interfaces at run-time use the <a href="../qtuitools/quiloader.html">QUiLoader</a>, found in the <a href="../qtuitools/qtuitools-index.html">Qt UI Tools</a> module.</p>
</div>
<p><b>See also </b><a href="../qtuitools/qtuitools-index.html">Qt UI Tools</a>.</p>
<!-- @@@QAbstractFormBuilder -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QAbstractFormBuilder$$$QAbstractFormBuilder -->
<h3 class="fn" id="QAbstractFormBuilder-1"><a name="QAbstractFormBuilder-1"></a>QAbstractFormBuilder::<span class="name">QAbstractFormBuilder</span>()</h3>
<p>Constructs a new form builder.</p>
<!-- @@@QAbstractFormBuilder -->
<!-- $$$~QAbstractFormBuilder[overload1]$$$~QAbstractFormBuilder -->
<h3 class="fn" id="dtor.QAbstractFormBuilder"><a name="dtor.QAbstractFormBuilder"></a><code>[virtual] </code>QAbstractFormBuilder::<span class="name">~QAbstractFormBuilder</span>()</h3>
<p>Destroys the form builder.</p>
<!-- @@@~QAbstractFormBuilder -->
<!-- $$$errorString[overload1]$$$errorString -->
<h3 class="fn" id="errorString"><a name="errorString"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QAbstractFormBuilder::<span class="name">errorString</span>() const</h3>
<p>Returns a human-readable description of the last error occurred in <a href="qabstractformbuilder.html#load">load</a>().</p>
<p>This function was introduced in Qt 5.0.</p>
<p><b>See also </b><a href="qabstractformbuilder.html#load">load</a>().</p>
<!-- @@@errorString -->
<!-- $$$load[overload1]$$$loadQIODevice*QWidget* -->
<h3 class="fn" id="load"><a name="load"></a><code>[virtual] </code><span class="type"><a href="../qtwidgets/qwidget.html">QWidget</a></span> *QAbstractFormBuilder::<span class="name">load</span>(<span class="type"><a href="../qtcore/qiodevice.html">QIODevice</a></span> *<i>device</i>, <span class="type"><a href="../qtwidgets/qwidget.html">QWidget</a></span> *<i>parent</i> = nullptr)</h3>
<p>Loads an XML representation of a widget from the given <i>device</i>, and constructs a new widget with the specified <i>parent</i>.</p>
<p><b>See also </b><a href="qabstractformbuilder.html#save">save</a>() and <a href="qabstractformbuilder.html#errorString">errorString</a>().</p>
<!-- @@@load -->
<!-- $$$save[overload1]$$$saveQIODevice*QWidget* -->
<h3 class="fn" id="save"><a name="save"></a><code>[virtual] </code><span class="type">void</span> QAbstractFormBuilder::<span class="name">save</span>(<span class="type"><a href="../qtcore/qiodevice.html">QIODevice</a></span> *<i>device</i>, <span class="type"><a href="../qtwidgets/qwidget.html">QWidget</a></span> *<i>widget</i>)</h3>
<p>Saves an XML representation of the given <i>widget</i> to the specified <i>device</i> in the standard UI file format.</p>
<p><b>Note: </b>Unlike when saving a form in Qt Designer, all property values are written. This is because, the state of whether a property value was modified or not isn't stored in the Qt property system. The widget that is being saved, could have been created dynamically, not loaded via <a href="qabstractformbuilder.html#load">load</a>(), so in this case the form builder isn't aware of the list of changed properties. Also, there's no generic way to do this for widgets that were created dynamically.</p><p>Therefore, you should remove properties that are not required from your resulting XML files, before loading them. Alternatively, if you already know which properties you want to save when you call this method, you can overload <code>computeProperties()</code> and return a filtered list of required properties. Otherwise, unexpected behavior may occur as some of these properties may depend on each other.</p>
<p><b>See also </b><a href="qabstractformbuilder.html#load">load</a>().</p>
<!-- @@@save -->
<!-- $$$setWorkingDirectory[overload1]$$$setWorkingDirectoryconstQDir& -->
<h3 class="fn" id="setWorkingDirectory"><a name="setWorkingDirectory"></a><span class="type">void</span> QAbstractFormBuilder::<span class="name">setWorkingDirectory</span>(const <span class="type"><a href="../qtcore/qdir.html">QDir</a></span> &amp;<i>directory</i>)</h3>
<p>Sets the current working directory of the form builder to the specified <i>directory</i>.</p>
<p><b>See also </b><a href="qabstractformbuilder.html#workingDirectory">workingDirectory</a>().</p>
<!-- @@@setWorkingDirectory -->
<!-- $$$workingDirectory[overload1]$$$workingDirectory -->
<h3 class="fn" id="workingDirectory"><a name="workingDirectory"></a><span class="type"><a href="../qtcore/qdir.html">QDir</a></span> QAbstractFormBuilder::<span class="name">workingDirectory</span>() const</h3>
<p>Returns the current working directory of the form builder.</p>
<p><b>See also </b><a href="qabstractformbuilder.html#setWorkingDirectory">setWorkingDirectory</a>().</p>
<!-- @@@workingDirectory -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
